<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="议题名称">
        <el-input
          v-model="queryParams.eventTitle"
          placeholder="请输入议题名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="议题类型">
        <el-select
          v-model="queryParams.eventType"
          placeholder="请选择议题类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.yitileixing"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="postList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="审议议题" align="center" prop="eventTitle" />
      <el-table-column label="提议单位" align="center" prop="proposeCompany" />
      <el-table-column label="议题类型" align="center" prop="eventType">
        <template slot-scope="scope">{{
          getDictLabel(
            dict.type.yitileixing,
            scope.row.eventType,
            "value",
            "label"
          )
        }}</template>
      </el-table-column>
      <el-table-column label="申请日期" align="center" prop="eventCreateTime" />
      <el-table-column label="状态" align="center" prop="eventStatus">
        <template slot-scope="scope">{{
          getDictLabel(eventStatusOptions, scope.row.eventStatus)
        }}</template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="toView(scope.row)"
            >查看</el-button
          >
          <el-button size="mini" type="text" @click="toApproval(scope.row)"
            >审批</el-button
          >
          <!-- 删除 -->
          <el-button size="mini" type="text" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog
      :title="title"
      top="2vh"
      class="abow_dialog"
      :visible.sync="visible"
      style="height: 520px"
      width="1050px"
      append-to-body
    >
      <detail :formData="formData" :visible="visible" />
    </el-dialog>
    <!-- 打开事项审批的界面 -->
    <el-dialog
      :title="title"
      top="2vh"
      class="abow_dialog"
      :visible.sync="visibleApprovalDialog"
      style="height: 520px"
      width="1050px"
      append-to-body
    >
      <shi-xiang-shen-pi :formData="formData" @callback="callback" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listPost,
  getPost,
  delPost,
  addPost,
  updatePost,
} from "@/api/majorIssues/shixiang.js";
import { getDictLabel } from "@/utils/Util.js";
import Detail from "../xiangqin";
import ShiXiangShenPi from "../shixiangshenpi";
export default {
  name: "Post",
  components: {
    Detail,
    ShiXiangShenPi,
  },
  dicts: ["yitileixing"],
  data() {
    return {
      getDictLabel: getDictLabel,
      // 审批弹窗
      visibleApprovalDialog: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      visible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        eventTitle: undefined, // 议题名称
        eventType: undefined, // 议题类型
      },
      // 状态
      eventStatusOptions: [
        {
          value: 0,
          label: "草稿",
        },
        {
          value: 1,
          label: "已提交",
        },
        {
          value: 2,
          label: "已完成",
        },
      ],
      // 表单参数
      form: {},

      // 查看的formData
      formData: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // handleDelete
    handleDelete(row) {
      const ids = [row.id];
      this.$modal
        .confirm("是否确认删除?")
        .then(function () {
          return delPost(ids);
        })
        .then((res) => {
          // code 200时候
          if (res.code == 200) {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          }
        })
        .catch(() => {});
    },
    /** 查询事项清单列表 */
    getList() {
      this.loading = true;
      listPost(this.queryParams).then((response) => {
        // this.postList = response.rows ;
        // let postList = [{
        //   eventTitle: "你好",
        //   eventType: "66666",
        //   eventCreateTime: "2024-01-01",
        //   eventStatus: 1,
        //   eventDetail: '议题内容44444',
        //   eventFileName: "需求2.doc"
        // }]
        let postList = response.rows;
        this.postList = postList;
        // this.postList =postList.map(item=>{
        //   let arr = this.eventStatusOptions.filter(status=>status.value == item.eventStatus);
        //   return {
        //     ...item,
        //     eventStatus: arr[0].label
        //   }
        // })
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.visible = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        eventTitle: undefined,
        postSort: 0,
        status: "0",
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.postId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.visible = true;
      this.title = "添加岗位";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const postId = row.postId || this.ids;
      getPost(postId).then((response) => {
        this.form = response.data;
        this.visible = true;
        this.title = "修改岗位";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.postId != undefined) {
            updatePost(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.visible = false;
              this.getList();
            });
          } else {
            addPost(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.visible = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 审批 */
    toApproval(row) {
      this.visibleApprovalDialog = true;
      this.formData = JSON.parse(JSON.stringify(row));
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/post/export",
        {
          ...this.queryParams,
        },
        `post_${new Date().getTime()}.xlsx`
      );
    },
    // 查看
    toView(row) {
      // 打开查看的对话框
      this.visible = true;
      this.formData = JSON.parse(JSON.stringify(row));
    },
    //
    callback() {
      this.visibleApprovalDialog = false;
    },
  },
};
</script>

<style scoped>
::v-deep .el-dialog {
  height: 900px;
}
</style>
